﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net.Http;
using Windows.Storage;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;

namespace CC98.Metro.Test
{
    [TestClass]
    public class HtmlParserUnitTest
    {
		/// <summary>
		/// 测试用 HTTP 客户端。
		/// </summary>
		private static HttpClient _client;

		/// <summary>
		/// 初始化。
		/// </summary>
		[ClassInitialize]
		public static void HtmlParserUnitTestInitialize(TestContext context)
		{
			_client = new HttpClient();
		}

		/// <summary>
		/// 清理。
		/// </summary>
		[ClassCleanup]
		public static void HtmlParserUnitTestCleanup()
		{
			_client.Dispose();
		}

        [TestMethod]
        public void TestHomeParser()
        {
			var html = _client.GetStringAsync("http://www.cc98.org").Result;

			var parser = new CC98.HtmlParser.HomePageParser();
			var result = parser.Parse(html);

			Assert.AreEqual(21, result.RootBoards.Count);
        }

		[TestMethod]
		public void TestListBoardsParser()
		{
			var html = _client.GetStringAsync("http://www.cc98.org/list.asp?boardid=5").Result;

			var parser = new CC98.HtmlParser.ListPageParser();

			var result = parser.Parse(html);

			Assert.AreEqual(16, result.Boards.Count);
			Assert.AreEqual(0, result.Topics.Count);
		}

		[TestMethod]
		public void TestListTopicsParser()
		{
			var html = _client.GetStringAsync("http://www.cc98.org/list.asp?boardid=537&page=1").Result;

			var parser = new CC98.HtmlParser.ListPageParser();

			var result = parser.Parse(html);
		}
    }
}
